<jsp:include page="../../header.jsp">
			<jsp:param value="item5" name="item"/>
</jsp:include> 
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.io.File"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%try {
			String tempfilePath = session.getAttribute("tempfilePath")
					.toString();
			if (tempfilePath != null) {
				File tempfile = new File(tempfilePath);
				if (tempfile.exists()) {
					tempfile.delete();
					if (tempfile.exists()) {
						System.out.println("------删除临时文件失败-------");
					} else {
						System.out.println("------删除打包产生的临时文件------");
					}
				}
			}
		} catch (Exception e) {
		} %>
<%String errormessage = null;
if(request.getAttribute("errormessage")!=null){
errormessage = request.getAttribute("errormessage").toString();
out.print("<script>alert('上传失败"+"!"+"请上传小于100M的文件')</script>");
}/* else{
	response.sendRedirect("applayReimAction!getTravelInfoList.action");
} */
%>
<section class="content">
	<section class="widget"  id="department" >
		<header>
			<span class="icon">&#128196;</span>
			<hgroup>
				<h1>报销申请表</h1>
				<h2>待报销列表</h2>
			</hgroup>
		</header>
		<div class="content">
			 <div id="bottomTabs" class="tabs" >
				<ul>
			    	<li>出差详情</li>
			    	<li  class="on">报销详情</li>
			    </ul>
			  <div class="hide">
				<p id="purtitle" align="center">
		<label for="purCode">出差单号:</label>
		<label for="purCode"><s:property value="businessTravelList.travelOrder"/></label>
		
		<label for="purCode">职工号:</label>
		<label for="purCode"><s:property value="businessTravelList.userInfoByUserid.userid"/></label>  
		
		<label for="purCode">职工姓名:</label>
		<label for="purCode"><s:property value="businessTravelList.userInfoByUserid.userName"/></label>
		<label for="purCode">开始时间:</label>
		<label for="purCode"><s:date name="businessTravelList.startTime" format="yyyy-MM-dd" /></label>
			<br />
		<label for="purCode">结束时间:</label>
		<label for="purCode"><s:date name="businessTravelList.endTime" format="yyyy-MM-dd" /></label>
		
		<label for="purCode">总预算:</label> 
		<label for="purCode"><s:property value="businessTravelList.amount"/></label>
	
		<label for="purCode">状态:</label> 
		<label for="purCode"><s:property value="businessTravelList.verifierStatus"/></label> 
		
		<label for="purCode">审批人:</label>
		<label for="purCode"><s:property value="businessTravelList.userInfoByVerifierId.userName"/></label>
		
	</p>
				<form  name="showTravelInfoList">
				<table id="myTable">
					<tr>
						<th>开始地点</th>
						<th>目的地</th>
						<th>距离/公里</th>
						<th>交通方式</th>
						<th>住宿</th>
						<th>餐饮费/天</th>
						<th>其他费用/天</th>
						<th>天数</th>
						<th>本次费用/元</th>
					</tr>
					<s:iterator value="businessTravels" id="row" status="state">
						<tr>
							 <td align="center">
								<s:property value="#row.startPlace"/>
							</td>
							 <td align="center">
							 	<s:property value="#row.endPlace"/>
							</td>
							<td align="center">
								<s:property value="#row.distance"/>
							</td>
							<td align="center">
								<s:property value="#row.travelStandard.traffic.traffic"/>
							</td>
							<td align="center">
								<s:property value="#row.travelStandard.hotel.hotel"/>
							</td>
							<td align="center">
								<s:property value="#row.travelStandard.mealsCost"/>
							</td>
							<td align="center">
								<s:property value="#row.travelStandard.elseCost"/>
							</td>
							<td align="center">
								<s:property value="#row.time"/>
							</td>
							<td align="center">
								<s:property value="#row.sum"/>
							</td>
						</tr>
					</s:iterator>
				</table>
				</form>
				
				<p id="back"><a href="applayReimAction!getNoApplayTravelList.action">
				<input type="button" class="white" id="submit" value="返回报销申请" >
				</a></p>
				
			 </div>
			
					<div class="show">
						<form  action="applayReimAction!saveApplayReim.action" method="post">
						<p id="purtitle" >
						<label for="purCode">报销单号</label> <input type="hidden" readonly name="applayReim.applayFileId"
								value="<s:property value="businessTravelList.travelOrder"/>">
							<input type="hidden" readonly name="applayReim.travelOrder"
								value="<s:property value="businessTravelList.travelOrder"/>">
								<label for="purCode"><s:property value="businessTravelList.travelOrder"/></label>
							<label for="purCode">报销时间</label>
							<s:if test="applayReim.applayTime!=null">
							<input type="hidden" readonly  name="applayReim.applayTime"
								value="<s:date name="applayReim.applayTime" format="yyyy-MM-dd" />">
								<label for="purCode"><s:date name="applayReim.applayTime" format="yyyy-MM-dd" /></label>
							</s:if>
							<s:else>
								<%SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 格式化时间输出
								String date =sdf.format(new Date());
								%>
							<input type="hidden" readonly name="applayReim.applayTime"
								value="<%=date%>">
								<label for="purCode"><%=date %></label>
							</s:else>
							
							<label for="purCode">职工号</label> <input type="hidden" readonly name="applayReim.userInfo.userid"
								value="<s:property value="businessTravelList.userInfoByUserid.userid"/>"> 
								<label for="purCode"><s:property value="businessTravelList.userInfoByUserid.userid"/></label>
							<label for="purCode">职工姓名</label> <input type="hidden" readonly name="applayReim.userInfo.userName"
								value="<s:property value="businessTravelList.userInfoByUserid.userName"/>">
								<label for="purCode"><s:property value="businessTravelList.userInfoByUserid.userName"/></label>
								<br/>
								
							<label for="purCode">预算费用</label> <input type="hidden" readonly name="applayReim.amount" id="amount"
								value=<s:property value="businessTravelList.amount"/>>
							<label for="purCode"><s:property value="businessTravelList.amount"/></label>
								<s:if test="applayReim.appAmount!=0.00">
							<label for="purCode">申请报销费用/元</label> <input type="text"  name="applayReim.appAmount" id="appAmount" maxlength="12" onchange="countSavecost();" onkeyup="this.value = this.value.replace(/[^\d.]/g,'')"  onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')"
										value=<s:property value="applayReim.appAmount"/>>
							<input type="hidden" readonly name="applayReim.realAppAmount" id="realAppAmount" 
										value=<s:property value="applayReim.realAppAmount"/>>
							<input type="hidden" readonly name="applayReim.saveCost" id="saveCost"
								value=<s:property value="applayReim.saveCost"/>>
								</s:if>
								<s:else>
							<label for="purCode">申请报销费用/元</label> <input type="text"  name="applayReim.appAmount" id="appAmount" maxlength="12" onchange="countSavecost();" onkeyup="this.value = this.value.replace(/[^\d.]/g,'')"  onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')"
										value=0>
							<input type="hidden" readonly name="applayReim.realAppAmount" id="realAppAmount" 
										value=0>
							<input type="hidden" readonly name="applayReim.saveCost" id="saveCost"
								value=<s:property value="0"/>>
							
								</s:else>
						
							
						</p>
						<s:if test="applayReim.applayTime!=null">
						<% 
				int receiptssize = 0;
				if(request.getAttribute("receiptssize")!=null)
				{
					receiptssize = Integer.valueOf(request.getAttribute("receiptssize").toString());
					if(receiptssize>0){
			%>
							<table id="myTable">
								<tr>
									<th colspan="2">收据类型</th>
									<th>文件名</th>
									<th>备注</th>
									<th colspan="2">操作</th>
								</tr>
								
								
								<s:iterator value="#request.traficeFileMap" status="stuts">
										<tr>
											<td><input name="url" type="checkbox" id="url"
												value="<s:property value="key" />,<s:property value="key" />">
											</td>
											<td>
												交通
											</td>
											<td>
											  <s:property value="key" /> 
											</td>
											<td>
												 <s:property value="value" /> 
											</td>
											<td><input type ="button" class="button white" value="下载" 
												onclick="downloadFile1('<s:property value="key" />','<s:property value="key" />')" />
											</td>
											<td><input type ="button"  class="button white" value="删除" 
												onclick="deleteFile1('<s:property value="key" />','<s:property value="key" />','<s:property value="applayReim.travelOrder"/>')" />
											</td>
										</tr>
										
								</s:iterator>
								
								<s:iterator value="#request.mealFileMap" status="stuts">
								
										<tr>
											<td><input name="url" type="checkbox" id="url"
												value="<s:property value="key" />,<s:property value="key" />">
											</td>
											<td>
												餐饮
											</td>
											<td>
											  <s:property value="key" /> 
											</td>
											<td>
												 <s:property value="value" /> 
											</td>
											<td><input type ="button" value="下载"  class="white"
												onclick="downloadFile1('<s:property value="key" />','<s:property value="key" />')" />
											</td>
											<td><input type ="button" value="删除"  class="white"
												onclick="deleteFile1('<s:property value="key" />','<s:property value="key" />','<s:property value="applayReim.travelOrder"/>')" />
											</td>
										</tr>
									
								</s:iterator>
								
								<s:iterator value="#request.hotelFileMap" status="stuts">
								
										<tr>
											<td><input name="url" type="checkbox" id="url"
												value="<s:property value="key" />,<s:property value="key" />">
											</td>
											<td>
												住宿
											</td>
											<td>
											  <s:property value="key" /> 
											</td>
											<td>
												 <s:property value="value" /> 
											</td>
											<td><input type ="button" value="下载"  class="white"
												onclick="downloadFile1('<s:property value="key" />','<s:property value="key" />')" />
											</td>
											<td><input type ="button" value="删除"  class="white"
												onclick="deleteFile1('<s:property value="key" />','<s:property value="key" />','<s:property value="applayReim.travelOrder"/>')" />
											</td>
										</tr>
										
								</s:iterator>
								
								<s:iterator value="#request.elseFileMap" status="stuts">
										<tr>
											<td><input name="url" type="checkbox" id="url"
												value="<s:property value="key" />,<s:property value="key" />">
											</td>
											<td>
												其他
											</td>
											<td>
											  <s:property value="key" /> 
											</td>
											<td>
												 <s:property value="value" /> 
											</td>
											<td><input type ="button" value="下载" class="white"
												onclick="downloadFile1('<s:property value="key" />','<s:property value="key" />')" />
											</td>
											<td><input type ="button" value="删除"  class="white"
												onclick="deleteFile1('<s:property value="key" />','<s:property value="key" />','<s:property value="applayReim.travelOrder"/>')" />
											</td>
										</tr>
										
								</s:iterator>
							</table>
							<div align="center">
							
							<input type="button" id="submit" value="添加发票" class="white" onclick="showWin()" />
								<input class="white" title="选择下载的文件"
									onClick="SelectAll(this.form)" type="button"  value="全选"> 
								<input class="white" title="反向选择下载文件" onClick="TurnOver(this.form)"
									type="button"   value="反选"> 
								<input class="white" title="下载选中文件" onClick="DownlodSelected(this.form)" type="button"
									value="批量下载文件">
							</div>
							<%} }
							
							if(receiptssize==0){
							%>
							<h2 align="center"><font color="red">请上传发票并填写申请报销费用</font></h2>
							<p id="back">
							<input type="button" id="submit" value="上传发票" class="white" onclick="showWin()" />
							<%} %>
							<input type="hidden" id="receiptssize" value='<%=receiptssize %>'>
							
						</s:if>
						<s:else>
						<input type="hidden" id="receiptssize" value=0>
							<h2 align="center"><font color="red">请上传发票并填写申请报销费用</font></h2>
							<p id="back">
							<input type="button" class="white" id="submit" value="上传发票" onclick="showWin()" />
						</s:else>
						
						<input type="submit" class="white" value="提交申请" onclick="return makesure()"/>
						<a href="applayReimAction!getNoApplayTravelList.action">
						<input type="button" class="white" id="submit" value="返回报销申请" >
						</a>
						</p>
						</form>
					</div>
			</div>
		</div>
<div id="popup" class="hide">
		<a href="javascript:closeWin()" id="close">关闭</a><br>
		<div class="form-div">
			<form id="reg-form" action="uploadFileAction.action" theme="simple" enctype="multipart/form-data" method="post">
			
				<table>
				<tr><td>
				<label for="purCode">文件类型：</label> 
					  <select name="receipt.fileType" >
						  <option value="交通">交通</option> 
						  <option value="餐饮">餐饮</option> 
						  <option value="住宿">住宿</option>
						  <option value="其他">其他</option> 
						</select> 
						</td>
				</tr>
				<tr>
				<td>
				<label for="purCode">文件说明：</label> 
					  <textarea rows="" cols="" name="receipt.remark" maxlength="100"></textarea>
					  <font color="#dd0000">选填，可输入100字</font>
					  </td>
				</tr>
					<tr>
					<td id="more">
					<input type="text" size="20" name="upfile" id="upfile" readonly> 
					<input type="button" value="上传文件"  class="button white"onclick="path.click()"> <font color="#dd0000">上传小于100M的文件</font>
					<s:file name="file" multiple="true"
							id="path" style="display:none" onchange="upfile.value=this.value" ></s:file>
					<!-- <input type="button" value="上传发票多个" onclick=addMore(); > -->
				</td>
					</tr>
				</table>
				
				<div class="buttons">
					<input value="确定" type="submit" class="button white" id="submitfile">
					<input value="重置" type="reset" class="button white" id="reset">
				</div>
				
				<input type="hidden" name="receipt.id.applayFileId" value="<s:property value="businessTravelList.travelOrder"/>">
				<s:if test="applayReim.applayTime!=null">
			<input type="hidden"  name="applayReim.applayTime" value="<s:date name="applayReim.applayTime" format="yyyy-MM-dd" />">
		</s:if>
		<s:else>
			<%SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 格式化时间输出
			String date =sdf.format(new Date());%>
			<input type="hidden"  name="applayReim.applayTime"
			value="<%=date%>">
		</s:else>
		
		<input type="hidden"  name="applayReim.userInfo.userid"
			value="<s:property value="businessTravelList.userInfoByUserid.userid"/>">
		<s:if test="applayReim.appAmount!=0.00">
				<input type="hidden"  name="applayReim.appAmount" id="appAmount1" 
					value=<s:property value="applayReim.appAmount"/>>
				<input type="hidden"  name="applayReim.saveCost" id="saveCost1"
			value=<s:property value="applayReim.saveCost"/>>
			<input type="hidden"  name="applayReim.realAppAmount" id="realAppAmount1"
			value=<s:property value="applayReim.realAppAmount"/>>
			</s:if>
			<s:else>
				<input type="hidden"  name="applayReim.appAmount" id="appAmount1" 
					value=0>
				<input type="hidden"  name="applayReim.realAppAmount" id="realAppAmount1"
			value=0>
				<input type="hidden" name="applayReim.saveCost" id="saveCost1"
			value=<s:property value="0"/>>
			</s:else>
		<input type="hidden" readonly name="applayReim.amount"
			value=<s:property value="businessTravelList.amount"/>>
		<input type="hidden" readonly name="applayReim.applayFileId"
			value="<s:property value="businessTravelList.travelOrder"/>">
		<input type="hidden" readonly name="applayReim.travelOrder"
			value="<s:property value="businessTravelList.travelOrder"/>">
			</form>
		</div>
	</div>
</section>
	<script type="text/javascript">
		var submit = document.getElementById("submitfile");
		var filepath = document.getElementById("path");
		
		submit.onclick=function(){
			if(filepath.value==""){
				alert("您还没有上传文件");
				return false;
			}
			else if(document.getElementById("appAmount1").value=="")
			{
				document.getElementById("appAmount1").value=0;
			}
			return true;
		}
	//删除文件
	function deleteFile1(filenames, filepaths,travelorder){
	if(confirm("是否删除")){
		location.href = encodeURI("downloadAction!deleteFile.action?filenames=" + filenames
				+ "&filepaths=" + filepaths+ "&travelorder=" + travelorder, "utf-8");
	}
		
	}
	//下载文件
	function downloadFile1(filenames, filepaths) {
		location.href = encodeURI("downloadAction.action?filenames=" + filenames
				+ "&filepaths=" + filepaths, "utf-8");
	}
	function SelectAll(oForm) {
		for ( var i = 0; i < oForm.url.length; i++) {
			oForm.url[i].checked = true;
		}
	}
	function TurnOver(oForm) {
		for ( var i = 0; i < oForm.url.length; i++) {
			oForm.url[i].checked = !oForm.url[i].checked;
		}
	}
	function DownlodSelected(oForm) {
		if (confirm("因需要在服务端动态打包,需要时间比较长,是否继续批量下载?")) {
			var arrDownloadList = [];
			for ( var i = 0; i < oForm.url.length; i++) {
				if (oForm.url[i].checked == true) {
					if (arrDownloadList.length == 0) {
						arrDownloadList[0] = oForm.url.value;
					}
					arrDownloadList[arrDownloadList.length] = oForm.url[i].value;
				}
			}
			if (arrDownloadList.length > 0) {
				var temp = [];
				var filenames = "";
				var filepaths = "";
				for ( var i = 1; i < arrDownloadList.length; i++) {
					temp = arrDownloadList[i].split(",")
					if (filenames == "" && filepaths == "") {
						filenames = temp[0]
						filepaths = temp[1]
					} else {
						filenames = filenames + "|" + temp[0];
						filepaths = filepaths + "|" + temp[1];
					}
				}
				downloadFile1(filenames, filepaths);
			} else {
				alert("还没有选中下载项");
			}
		}
	}
	//改动隐藏值
	function countSavecost(){
		var appAmount = document.getElementById("appAmount").value;
		document.getElementById("appAmount1").value = appAmount;
	}
	//弹出框
	function showWin() {
			var popup = document.getElementById("popup");
			popup.className = "show";
			popup.style.position = "fixed";
			popup.style.top = "50%";
			popup.style.left = "50%";
			popup.style.marginTop = "-225px";
			popup.style.marginLeft = "-215px";
			popup.style.width = "430px";
			popup.style.height = "450px";
			popup.style.zIndex = "101";

			var mybg = document.createElement("div");
			mybg.setAttribute("id", "mybg");
			mybg.style.background = "#000";
			mybg.style.width =document.body.scrollWidth+"px";
			mybg.style.height = document.body.scrollHeight+"px";
			mybg.style.position = "absolute";
			mybg.style.top = "0";
			mybg.style.left = "0";
			mybg.style.zIndex = "100";
			mybg.style.opacity = "0.3";
			mybg.style.filter = "Alpha(opacity=30)";
			document.body.appendChild(mybg);
			document.body.style.overflow = "auto";
		}
		function closeWin() {
			var popup = document.getElementById("popup");
			popup.className = "hide";
			var mybg = document.getElementById("mybg");
			mybg.parentNode.removeChild(mybg);
		}
		function makesure(){
			var obj = document.getElementById("receiptssize").value;
			var appAmount = document.getElementById("appAmount").value;
			
			if(appAmount=="")
			{
				alert("请输入申请报销费用");
				return false;
			}else if(!(/^-?\d+\.?\d{0,2}$/.test(appAmount))){
				alert("请输入范围在000000000.00~999999999.99的至多两位小数的数字");
				return false;
			}
			if(obj==0){
			
				alert("请上传发票");
				return false;
			}else{
				alert("提交成功");
				return true;
			}
			
		}

</script>
<%@ include file="../../footer.jsp" %>